<template>
  <div class="share-page">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item>数据中心</el-breadcrumb-item>
      <el-breadcrumb-item>商品分析</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/product-analysis' }"
        >商品优化分析</el-breadcrumb-item
      >
    </el-breadcrumb>
    <div class="abnormal-page">
      <div class="title">商品优化分析</div>
      <div class="choice-list">
        <div class="choice-item">
          <div class="choice-title">设备名称</div>
          <el-input
            v-model="formInline.device"
            placeholder="请输入设备名称"
          ></el-input>
        </div>
        <div class="choice-item">
          <div class="choice-title">设备编号</div>
          <el-input
            v-model="formInline.deviceCode"
            placeholder="请输入设备编号"
          ></el-input>
        </div>
        <div class="choice-item">
          <div class="choice-title">路线</div>
          <el-select v-model="formInline.seachLine" placeholder="请选择路线">
            <el-option
              v-for="i in lineOptions"
              :key="i.value"
              :label="i.label"
              :value="i.value"
            />
          </el-select>
        </div>
        <div class="choice-item">
          <div class="choice-title">补货员</div>
          <el-select
            v-model="formInline.seachReplenishman"
            placeholder="请选择补货员"
          >
            <el-option
              v-for="i in replenishmanOptions"
              :key="i.value"
              :label="i.label"
              :value="i.value"
            />
          </el-select>
        </div>
      </div>
      <div class="left-box">
        <div class="choice-btn">
          <el-button round :icon="Search" color="#0071bb">查询</el-button>
          <el-button round :icon="RefreshLeft">重置</el-button>
        </div>
      </div>
      <div class="title2">
        <div class="top-tabs">
          <div
            v-for="item in tabsList"
            :key="item.index"
            :class="activeIndex === item.index ? 'activity-item' : ''"
            class="tabs-item"
            @click="cutTabs(item)"
          >
            {{ item.name }}
          </div>
        </div>
        <el-button
          round
          :icon="Setting"
          color="#0071bb"
          size="small"
          @click="dialogVisible = true"
          >优化设置</el-button
        >
      </div>
      <div class="tables">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="id" label="设备名称" width="80px" />
          <el-table-column prop="open_time" label="设备编号" />
          <el-table-column prop="close_time" label="线路" />
          <el-table-column prop="pay_time" label="补货员" />
          <el-table-column prop="pay_method" label="状态" />
          <el-table-column prop="order_num" label="更换商品" />
          <el-table-column prop="order_type" label="减少补货"></el-table-column>
          <el-table-column prop="name" label="增加补货" />
          <el-table-column prop="imei" label="7日均销售额" />
          <el-table-column prop="check" label="操作">
            <template #default>
              <div class="check-text" @click="lookFuc">查看</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="page_number">
        <el-pagination
          v-model:current-page="pager.currentPage"
          v-model:page-size="pager.pageSize"
          layout="prev, pager, next, jumper,total"
          :total="pager.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <el-dialog
      v-model="dialogVisible"
      title="商品分析配置（修改后第二天生效）"
      width="1000"
      :show-close="true"
    >
      <div class="box-00ffff">
        说明：当自取柜的商品建议容量小于一定量的时候，每次去补货是没有必要的，系统默认是小于7个会建议下架，您可以自行调整
      </div>
      <div class="flex-start">
        下架建议标准：根据分析后的结果，系统建议补货数量小于
        <el-input v-model="num" placeholder="请输入个数" />个，建议更换商品。
      </div>
      <div class="box-00ffff">
        说明：有些商品是和品牌合作，或者必须处理的临期商品，不管销量如何，都不能下架，标记之后，系统不会再做优化建议
      </div>
      <div>
        <el-upload
          class="avatar-uploader"
          action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <el-icon v-else class="avatar-uploader-icon">
            <Plus />
          </el-icon>
        </el-upload>
        <span style="margin-left: 30px">特殊标记商品</span>
      </div>
      <template #footer>
        <div class="bottom-btn">
          <el-button round color="#0071bb">保存</el-button>
          <el-button @click="dialogVisible = false" round>取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { Search, RefreshLeft, Setting, Plus } from "@element-plus/icons-vue";
import type { UploadProps } from "element-plus";
import { useRouter } from "vue-router";
// 搜索表单数据
const formInline = ref({
  seachLine: "",
  seachReplenishman: "",
  deviceCode: "",
  device: "",
});

const lineOptions = ref([
  {
    label: "线路1",
    value: 1,
  },
  {
    label: "线路2",
    value: 0,
  },
]);
const replenishmanOptions = ref([
  {
    label: "补货员1",
    value: 1,
  },
  {
    label: "补货员2",
    value: 0,
  },
]);
// tab数据
const activeIndex = ref("1");
const tabsList = [
  {
    name: "按建议更换商品种类",
    index: "1",
  },
  {
    name: "按建议减少补货商品种类",
    index: "2",
  },
  {
    name: "按建议增加补货商品种类",
    index: "3",
  },
  {
    name: "按7日均销售额",
    index: "4",
  },
  {
    name: "按7日均销售量",
    index: "5",
  },
];
const cutTabs = (tabItem: tabsList) => {
  activeIndex.value = tabItem.index;
};
interface tabsList {
  name: string;
  index: string;
}
// 表格数据
const tableData = [
  {
    id: "1",
    open_time: "2024-12-01 12:00:00",
    close_time: "2024-12-01 12:00:00",
    pay_time: "2024-12-01 12:00:00",
    pay_method: "微信",
    order_num: "87434893841",
    order_type: "扣款异常",
    name: "伯克材料3668649",
    imei: "8698254043668649",
    tell: "139849894494",
    personnel: "小郑",
    check: "详情",
  },
  {
    id: "2",
    open_time: "2024-12-01 12:00:00",
    close_time: "2024-12-01 12:00:00",
    pay_time: "2024-12-01 12:00:00",
    pay_method: "支付宝",
    order_num: "87434893841",
    order_type: "开门异常",
    name: "伯克材料3668649",
    imei: "8698254043668649",
    tell: "139849894494",
    personnel: "小郑",
    check: "详情",
  },
  {
    id: "3",
    open_time: "2024-12-01 12:00:00",
    close_time: "2024-12-01 12:00:00",
    pay_time: "2024-12-01 12:00:00",
    pay_method: "支付宝",
    order_num: "87434893841",
    order_type: "关门异常",
    name: "伯克材料3668649",
    imei: "8698254043668649",
    tell: "139849894494",
    personnel: "小郑",
    check: "详情",
  },
  {
    id: "4",
    open_time: "2024-12-01 12:00:00",
    close_time: "2024-12-01 12:00:00",
    pay_time: "2024-12-01 12:00:00",
    pay_method: "金币",
    order_num: "87434893841",
    order_type: "识别异常",
    name: "伯克材料3668649",
    imei: "8698254043668649",
    tell: "139849894494",
    personnel: "小郑",
    check: "详情",
  },
  {
    id: "4",
    open_time: "2024-12-01 12:00:00",
    close_time: "2024-12-01 12:00:00",
    pay_time: "2024-12-01 12:00:00",
    pay_method: "金币",
    order_num: "87434893841",
    order_type: "已处理",
    name: "伯克材料3668649",
    imei: "8698254043668649",
    tell: "139849894494",
    personnel: "小郑",
    check: "详情",
  },
];
// 分页
const pager = ref({
  currentPage: 1,
  pageSize: 10,
  total: 10,
}); // 改变pageSize
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
};
// 改变当前页码 currentPage
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
};
// 优化设置弹窗
const dialogVisible = ref(false);
const num = ref(0);
const imageUrl = ref("");
const handleAvatarSuccess: UploadProps["onSuccess"] = (
  response,
  uploadFile
) => {
  imageUrl.value = URL.createObjectURL(uploadFile.raw!);
};
// 查看按钮
const router = useRouter();
const lookFuc = () => {
  router.push("/product-analysis-look");
};
</script>

<style lang="scss" scoped>
.abnormal-page {
  background-color: #fff;
  margin-top: 10px;
  padding: 10px;

  .title {
    font-size: 16px;
    color: #000;
    padding: 10px;
  }
  .left-box {
    display: flex;
    justify-content: end;
    align-items: center;
    margin-left: 20px;
    .choice-btn {
      display: flex;
      justify-content: left;
    }
  }
  .title2 {
    background: #d9d9d9;
    color: #4d4d4d;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0px 20px;
    margin: 10px 0px;
  }

  .top-tabs {
    text-align: center;
    display: flex;
    font-weight: bold;
    font-size: 14px;
    padding: 10px;

    .tabs-item {
      padding: 5px 10px;
      background-color: #fff;
      border: 1px solid #d2d2d2;
      border-radius: 20px;
      margin-right: 15px;
      min-width: 100px;
      font-size: 14px;
      font-weight: normal;
    }
    .tabs-item:first-child() {
      width: 100px !important;
    }

    .activity-item {
      background-color: #0071bb;
      border: 1px solid #0071bb;
      color: #fff;
    }

    .tabs-item:hover {
      cursor: pointer;
    }
  }

  .choice-list {
    display: flex;
    flex-wrap: wrap;
    padding: 10px 0;

    .choice-item {
      width: 25%;
      display: flex;
      align-items: center;
      margin-bottom: 10px;

      .el-select {
        width: 250px;
      }

      .choice-title {
        font-size: 12px;
        width: 100px;
        text-align: center;
      }

      .rounded-input {
        width: 250px;
      }
    }
  }

  .tables {
    .check-text {
      color: #0071bb;
      cursor: pointer;
    }
  }
}
.box-00ffff {
  background: #00ffff;
  width: 100% !important;
  padding: 6px;
  margin: 14px 0px;
}
.flex-start {
  display: flex;
  align-items: center;
  justify-content: start;
  margin: 14px 0px;
  .el-input {
    width: 60px !important;
  }
}
.avatar-uploader .avatar {
  width: 160px;
  height: 160px;
  display: block;
}
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  margin: 14px 0px;
  font-size: 28px;
  color: #8c939d;
  width: 160px;
  height: 160px;
  text-align: center;
  background: #dcdada;
}
</style>
